package test;

import java.io.IOException;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.util.Bytes;

public class Drop {
	public static Configuration configuration;
	public static Connection connection;
	public static Admin admin;

	public static void init() {
		configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase");
		try {
			connection = ConnectionFactory.createConnection(configuration);
			admin = connection.getAdmin();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void close() {
		try {
			if (admin != null)
				admin.close();
			if (null != connection)
				connection.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void clearRows(String name) throws IOException {
		init();
		admin.disableTable(TableName.valueOf(name));
		admin.deleteTable(TableName.valueOf(name));
	}

	public static void main(String[] args) throws IOException {
		Drop d = new Drop();
		d.clearRows("student");
		System.out.println("student表已清空");
	}
}
